// 时间格式转换  1:8:8  变成 01:08:08的时间格式
const formatTime = num => {
  return num < 10 ? `0` + num : num;
};

// 获取当前时间（2018-04-09  或者 2018-04-15 12:22:14）两种格式
const getTime = i => {
  let d = new Date();
  let time =
    d.getFullYear() +
    "-" +
    formatTime(d.getMonth() + 1) +
    "-" +
    formatTime(d.getDate());
  if (i === 1) {
    time =
      time +
      `  ` +
      formatTime(d.getHours()) +
      ":" +
      formatTime(d.getMinutes()) +
      ":" +
      formatTime(d.getSeconds());
  }
  return time;
};

const randomVal = arr => {
  let len = arr.length;
  let i = Math.floor(Math.random() * len);
  return arr[i];
};
module.exports = {
  getTime,
  randomVal
};
